package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.entity.NursingPlan;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "护理计划")
@RestController
@RequestMapping("/nursing/plan")
public class NursingPlanController extends BaseController {
    @Autowired
    private NursingPlanService nursingPlanService;

    @GetMapping
    @ApiOperation("查询所有护理计划")
    public ResponseResult<List<NursingPlanVo>> getAll() {
        List<NursingPlanVo> lists = nursingPlanService.getAll();
        return success(lists);
    }

    @PostMapping
    @ApiOperation("新增护理计划")
    public ResponseResult add(@RequestBody NursingPlanDto dto) {
        nursingPlanService.add(dto);
        return success();
    }

    @GetMapping("/search")
    @ApiOperation("分页查询护理计划")
    public ResponseResult<PageResponse> getByPage(@ApiParam("护理计划名称") String name,
                                    @ApiParam("当前页码")
                                    @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                    @ApiParam("每页显示条数")
                                    @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                    @ApiParam("状态") Integer status) {
      PageResponse p=nursingPlanService.getByPage(name,pageNum,pageSize,status);

        return success(p);
    }

    @GetMapping("/{id}")
    @ApiOperation("查询护理计划")
    public ResponseResult<NursingPlanVo> getById(@PathVariable Long id){
        NursingPlanVo nursingPlanVo = nursingPlanService.getById(id);
        return success(nursingPlanVo);
    }

    @PutMapping
    @ApiOperation("根据id修改护理计划")
    public ResponseResult update(@RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.update(nursingPlanDto);
        return success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除护理计划")
    public ResponseResult deleteById(@PathVariable Long id){
        nursingPlanService.deleteById(id);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用禁用")
    public ResponseResult startOrStop(@PathVariable Long id,@PathVariable Long status){
        nursingPlanService.startOrStop(id,status);
        return success();
    }
}
